﻿using System.Collections;
using System.Collections.Generic;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.IO;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
   
    public partial class ITXEXRPT
    {
        public string TSTPrint(ref bool IsReturn)
        {
            if (app.company != "TST")
                return filename;
            Helper.GetDate(ref date, ref year, ref month, ref day);
            switch (DocType)
            {

                #region==TST==========
                case "TSTEK02":
                    destfolder = SetFolder(Root, "采购统计");
                    #region====文件命名==============
                    order = "采购统计" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTEK02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTEK02(dsSource);
                    break;
                case "TSTVK02":
                    destfolder = SetFolder(Root, "销售统计");
                    #region====文件命名==============
                    order = "销售统计" + date;
                    DestFile = destfolder + "\\" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTVK02";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVK02(dsSource);
                    break;
                case "TSTLB":
                    destfolder = SetFolder(Root, "标签");
                    #region====文件命名==============
                    order = DateTime.Now.ToLocalTime().ToFileTime().ToString();
                    DestFile = destfolder + "\\标签" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTLB";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTLB(dsSource);
                    exAgent.Close();
                    IsReturn = true; ;
                    break;
                case "TSTVALB":
                    destfolder = SetFolder(Root, "标签");
                    #region====文件命名==============
                    order = DateTime.Now.ToLocalTime().ToFileTime().ToString();
                    DestFile = destfolder + "\\标签" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTLABEL";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTLABEL(dsSource);
                    exAgent.Close();
                    IsReturn = true; ;
                    break;
                case "TSTVA06":
                    destfolder = SetFolder(Root, "品种列表");
                    #region====文件命名=============da=
                    order = date;
                    DestFile = destfolder + "\\品种列表" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTVA06";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVA06(dsSource);
                    break;
                case "TSTVK04":
                    destfolder = SetFolder(Root, "形式发票");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VKPOS"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VKPOS"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["VKPAUFKRS"].ToString().Trim();
                    LFD = dwOrder["VKPAUFLFD"].ToString().Trim();
                    order = KRS + Helper.GetSubRollNum(LFD);
                    DestFile = destfolder + "\\形式发票-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = "TSTVK04";
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVK04(dsSource);
                    break;
                case "TSTVK05":
                    destfolder = SetFolder(Root, "购销合同");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VKKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VKKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ORDERNO"].ToString().Trim();
                    order = KRS;
                    DestFile = destfolder + "\\购销合同-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVK05(dsSource);
                    break;
                case "TSTVKSMP":
                    destfolder = SetFolder(Root, "样布单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VKKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VKKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ORDERNO"].ToString().Trim();
                    order = KRS;
                    DestFile = destfolder + "\\样布确认单-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVKSMP(dsSource);
                    break;
                case "TSTEK05":
                    destfolder = SetFolder(Root, "采购");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("EKKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["EKKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ORDNO"].ToString().Trim();
                    order = KRS + "-" + dwOrder["SUPP"].ToString().Trim().Replace(" ", "-");
                    DestFile = destfolder + "\\OrderSheet-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTEK05(dsSource);
                    break;
                case "TSTEKSMP":
                    destfolder = SetFolder(Root, "采购");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("EKKOPF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["EKKOPF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = dwOrder["ORDNO"].ToString().Trim();
                    order = KRS + "-" + dwOrder["SUPP"].ToString().Trim().Replace(" ", "-");
                    DestFile = destfolder + "\\SampleLengthOrder-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTEKSMP(dsSource);
                    break;
                case "TSTVVSMP":
                    destfolder = SetFolder(Root, "发货单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VVLIEF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VVLIEF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = System.Convert.ToInt64(dwOrder["VVLIEFSCH"].ToString().Trim()) + "-" + Helper.GetGB2312Value(dwOrder["KDKUNDNA"].ToString().Trim());
                    order = KRS;
                    DestFile = destfolder + "\\发货单-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVVSMP(dsSource);
                    break;
                case "TSTVV05":
                    destfolder = SetFolder(Root, "发货单");
                    #region====文件命名==============
                    if (!dsSource.Tables.Contains("VVLIEF"))
                        IsReturn = true;
                    dwOrder = dsSource.Tables["VVLIEF"].Rows[0];
                    if (dwOrder == null)
                    {
                        IsReturn = true;
                    }
                    KRS = System.Convert.ToInt64(dwOrder["VVLIEFSCH"].ToString().Trim()) + "-" + Helper.GetGB2312Value(dwOrder["KDKUNDNA"].ToString().Trim());
                    order = KRS;
                    DestFile = destfolder + "\\发货单-" + order + ".xls";
                    #endregion
                    #region=====空白文档=======
                    Standard = order;
                    exAgent.CreateNewSheet(temp + ".xls", Standard);
                    tempfile = exAgent.FileName;
                    #endregion
                    TSTVV05(dsSource);
                    break;

                    #endregion

            }
            return filename;
        }

    }
}
